/**
 * 
 */
package handwritten.grid;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.util.ArrayList;

import utility.math.Vector2D;

/**
 * @author tioz
 *
 */
public class BasicInputGridTrainning extends BasicInputGrid implements Trainning{

	Font font;
	
	ArrayList<String> listToLearn;


	/**
	 * @param lineWidth
	 * @param textCellWidth
	 * @param textCellHeight
	 * @param textUnderlineHeight
	 */
	public BasicInputGridTrainning(int lineWidth, int textCellWidth,
			int textCellHeight, int textUnderlineHeight) {
		super(lineWidth, textCellWidth, textCellHeight, textUnderlineHeight);
		
		font       = new Font(getSystemFontList()[0],Font.ITALIC | Font.BOLD, 14);
		listToLearn= new ArrayList<String>();
	
		for (int c = 0x0000; c <= 0xFFFF; c++)
		{	
		  if (font.canDisplay((char)c))
		  {
			listToLearn.add(Character.toString((char)c));
		  }
		}
	}
	
	public static String[] getSystemFontList()
	{
	    return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
	
	}

	public static void terminalPrintFontList()
	{
	    String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
	    
	    for( int i = 0; i < fonts.length; i++ )
	    {
	      System.out.println(fonts[i]);
	    }	
	}
	
	
	public void paint(Graphics2D g2d){
		super.paint(g2d);
		g2d.setFont(font);
		g2d.setColor(new Color(200,0,60));
		for(int x=0;x< getNumberOfCellX();x++)
		{
			for(int y=1;y < getNumberOfCellY();y++)
			{
				Vector2D pos[] = getCellBoundary(x,y);
				g2d.drawString(String.valueOf(expectedChar(new int[]{x,y})),(int)pos[0].getX(),(int)pos[0].getY()+font.getSize());
			}	
		}		
	}


	/* (non-Javadoc)
	 * @see textRecognition.grid.Trainning#expectedChar(int, int)
	 */
	@Override
	public String expectedChar(int[] n) {
		int currentNumeberOfCell = n[0]+(n[1]-1)*getNumberOfCellX();
		if(currentNumeberOfCell < listToLearn.size())
			return listToLearn.get(currentNumeberOfCell);
		else 
			return "No Char";
	}

	/* (non-Javadoc)
	 * @see textRecognition.grid.Trainning#setExpectedChar(int[])
	 */
	@Override
	public void setExpectedChar(int[] n) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see textRecognition.grid.Trainning#charCollectionSize()
	 */
	@Override
	public int charCollectionSize() {
		return listToLearn.size();
	}
	
 
	
}
